using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Typing_GUI
{
    public partial class frmExamList : Form
    {
        public int userID=1;
        public frmExamList()
        {
            InitializeComponent();
        }
        void LoadExams()
        {
            List<CLASS.CToChucLuyenTap> examList = new List<Typing_GUI.CLASS.CToChucLuyenTap>();
            examList = CLASS.CToChucLuyenTap.GetExams();
            foreach (CLASS.CToChucLuyenTap exam in examList)
            {
                ListViewItem item = new ListViewItem();
                item.ImageIndex = 0;
                item.Text = exam.Tenluyentap;
                item.Tag = exam.Maluyentap;
                item.ToolTipText = exam.Mota;
                lvExamList.Items.Add(item);
            }
        }
        private void frmExamList_Load(object sender, EventArgs e)
        {
            LoadExams();
        }

        private void lvExamList_ItemActivate(object sender, EventArgs e)
        {
            if (lvExamList.SelectedItems.Count > 0)
            {
                frmExamTest frm = new frmExamTest();
                frm.examID = int.Parse(lvExamList.SelectedItems[0].Tag.ToString());
                frm.UserID = userID;
                frm.examName = lvExamList.SelectedItems[0].Text;
                frm.examDescription = lvExamList.SelectedItems[0].ToolTipText;
                frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
                frm.Show();
                this.Visible = false;
            }
        }

        private void btnPlay_Click(object sender, EventArgs e)
        {
            if (lvExamList.SelectedItems.Count > 0)
            {
                frmExamTest frm = new frmExamTest();
                frm.examID = int.Parse(lvExamList.SelectedItems[0].Tag.ToString());
                frm.UserID = userID;
                frm.examName = lvExamList.SelectedItems[0].Text;
                frm.examDescription = lvExamList.SelectedItems[0].ToolTipText;
                frm.FormClosed += new FormClosedEventHandler(MakeVisibleAgain);
                frm.Show();
                this.Visible = false;
            }
            else
            {
                MessageBox.Show("Please choice a exam to play!", "Message");
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void MakeVisibleAgain(object sender, FormClosedEventArgs e)
        {
            this.Close();
        }
    }
}